package org.example.mybatis.mapper;

import org.example.mybatis.annotation.Delete;
import org.example.mybatis.annotation.Insert;
import org.example.mybatis.annotation.Param;
import org.example.mybatis.annotation.Select;
import org.example.mybatis.annotation.Update;
import org.example.mybatis.entity.User;

import java.util.List;

/**
 * 使用注解方式的用户Mapper接口
 */
public interface UserAnnotationMapper {
    /**
     * 根据ID查询用户
     */
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(@Param("id") Long id);

    /**
     * 查询所有用户
     */
    @Select("SELECT * FROM user")
    List<User> selectAll();

    /**
     * 根据用户名和年龄查询用户
     */
    @Select("SELECT * FROM user WHERE username = #{username} AND age > #{age}")
    List<User> selectByUsernameAndAge(@Param("username") String username, @Param("age") Integer age);

    /**
     * 插入用户
     */
    @Insert("INSERT INTO user(username, password, age) VALUES(#{username}, #{password}, #{age})")
    int insert(User user);

    /**
     * 更新用户
     */
    @Update("UPDATE user SET username = #{username}, password = #{password}, age = #{age} WHERE id = #{id}")
    int update(User user);

    /**
     * 根据ID删除用户
     */
    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
}